#include "stdafx.h"

// Used to determine whether the DLL can be unloaded by OLE.
STDAPI DllCanUnloadNow( void ) {
	return _AtlModule.DllCanUnloadNow( );
}

// Returns a class factory to create an object of the requested type.
STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppv ) {
	return _AtlModule.DllGetClassObject( rclsid, riid, ppv );
}

// DllRegisterServer - Adds entries to the system registry.
// Registers object, typelib and all interfaces in typelib.
STDAPI DllRegisterServer( void ) {
	return _AtlModule.DllRegisterServer( );
}

// DllUnregisterServer - Removes entries from the system registry.
STDAPI DllUnregisterServer( void ) {
	return _AtlModule.DllUnregisterServer( );
}

// DllInstall - Adds/Removes entries to the system registry per user per machine.
STDAPI DllInstall( BOOL bInstall, LPCWSTR pszCmdLine ) {
	static const wchar_t szUserSwitch[] = L"user";
	HRESULT hr = E_FAIL;

	if ( pszCmdLine && !_wcsnicmp( pszCmdLine, szUserSwitch, _countof( szUserSwitch ) ) ) {
		ATL::AtlSetPerUserRegistration( true );
	}

	if ( bInstall ) {
		hr = DllRegisterServer( );
		if ( FAILED( hr ) ) {
			DllUnregisterServer( );
		}
	} else {
		hr = DllUnregisterServer( );
	}

	return hr;
}
